package com.wiscamp.ninechapters.problems.domain.models.problems.answers;

import com.wiscamp.ninechapters.problems.enums.AnswerTypes;
import com.wiscamp.ninechapters.problems.math.LatexText;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 表达式答案
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ExpressionAnswer extends Answer {
    /**
     * 答案值
     */
    private LatexText value;

    public ExpressionAnswer(long answerId, long questionId, int answerIndex, int groupIndex, LatexText value) {
        setAnswerId(answerId);
        setQuestionId(questionId);
        setAnswerIndex(answerIndex);
        setGroupIndex(groupIndex);

        this.value = value;

        var texType = value.getLatexType();
        switch (texType) {
            case PLUS_MINUS_EXPRESSION:
                setAnswerType(AnswerTypes.PLUS_MINUS_EXPRESSION);
                break;
            case TIMES_DIVISION_EXPRESSION:
                setAnswerType(AnswerTypes.TIMES_DIVISION_EXPRESSION);
                break;
            default:
                setAnswerType(AnswerTypes.ARITHMETIC_EXPRESSION);
                break;
        }

        setAnswerTypeId(this.getAnswerType().getValue());
    }

    @Override
    public String getAnswerText() {
        //this.setContentHypertext(value.getLatex());
        return value.getLatex();
    }
}
